package com.cloudstreamservice8002.service.impl;


import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloudstreamservice8002.entity.RouteInfo;
import com.cloudstreamservice8002.mapper.RouteInfoMapper;
import com.cloudstreamservice8002.service.RouteInfoService;
import com.cloudstreamservice8002.util.SnowflakeIdGenerator;
import com.google.common.base.Preconditions;
import org.springframework.stereotype.Service;

/**
* @author 26407
* @description 针对表【route_info】的数据库操作Service实现
* @createDate 2025-06-11 00:42:49
*/
@Service
public class RouteInfoServiceImpl extends ServiceImpl<RouteInfoMapper, RouteInfo>
    implements RouteInfoService {
    @Override
    public IPage<RouteInfo> getRouteInfo(Integer pageNum, Integer pageSize, String routeCode) {
        LambdaQueryWrapper<RouteInfo> queryWrapper = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(routeCode)) {
            queryWrapper.eq(RouteInfo::getRouteCode, routeCode);
        }
        return page(new Page<>(pageNum, pageSize), queryWrapper);
    }

    @Override
    public Boolean create(RouteInfo routeInfo) {
        Preconditions.checkNotNull(routeInfo);
        SnowflakeIdGenerator snowflakeIdGenerator = new SnowflakeIdGenerator(1, 1);
        routeInfo.setRouteCode(snowflakeIdGenerator.nextId().toString());
        return save(routeInfo);
    }

    @Override
    public Boolean updates(RouteInfo routeInfo) {
        Preconditions.checkArgument(routeInfo.getId() != null, "id不能为空");
        return updateById(routeInfo);
    }

    @Override
    public boolean removeRouteCode(String routeCode) {
        return remove(new QueryWrapper<RouteInfo>().eq("route_code", routeCode));
    }
}




